'''
Created on 02/03/2009

@author: eh01
'''
from urllib2 import URLError
from xml.dom import minidom
import base64
import unittest
import urllib2


class Test(unittest.TestCase):
    def setUp(self):
        pass
    def tearDown(self):
        pass
    def testGetMessagesTest(self):
        username = '' # Put in username here
        password = '' # Put in password here
        base64string = base64.encodestring(
                '%s:%s' % (username, password))[:-1]
        authheader =  "Basic %s" % base64string
        request = urllib2.Request("http://localhost:8080/node/5")
#        request = urllib2.Request("http://eplanning-vic-au.appspot.com/node/1")
        request.add_header("Authorization", authheader)
        try:
            response = urllib2.urlopen(request)
            xml_string = response.read()
            print xml_string
            xml = minidom.parseString(xml_string)
            messages_element = xml.getElementsByTagName("messages")[0]
            ids_element = messages_element.getElementsByTagName("id")
            for id_element in ids_element:
                # assume there is only one child node for that element
                child_node = id_element.childNodes[0]
                
                if child_node.nodeType == child_node.TEXT_NODE:
                    print "message id = " + child_node.data
        except URLError, e:
            print e.code

if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testGetMessagesTimeoutTest']
    unittest.main()